<template>
  <div class="login">
    <div class="login-box">
      <div class="login-banner"></div>
      <el-form :label-position="labelPosition" label-width="80px" :model="formLabelAlign">
        <h2>新子路管理系统软件</h2>
        <el-form-item label="">
          <el-input v-model="formLabelAlign.name" placeholder="请输入账号" prefix-icon="el-icon-user">
          </el-input>
        </el-form-item>
        <el-form-item label="">
          <el-input v-model="formLabelAlign.password" placeholder="请输入密码"
              prefix-icon="el-icon-s-goods"
              :show-password="true"
              auto-complete="new-password"
        ></el-input>
        </el-form-item>
        <el-form-item size="large">
           <el-button type="primary" style="width:100%" @click="Login">登录</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      labelPosition: "right",
      formLabelAlign: {
        name: "",
        password: ""
      },
      checked: true,
      input1: "",
      input2: "",
      usertoken:"",
      navsrole:"",
    };
  },
  created(){
    this.jump();
    // this.aa()
  },
  methods: {
    // async aa(){
    //   let a = await this.$api.home.aa()
    //   console.log(a);
    // },
    loginin(){
      console.log("111111");
    },
    jump(){
      let to = localStorage.getItem("token")
      if(to !== null){
        this.$router.replace("/operatingCenter");
      }
    },
    
    async Login() {
      let Login = (await this.$api.home.authLogin({
        username:this.formLabelAlign.name,
        password:this.formLabelAlign.password
      })).data
      
      this.usertoken = Login.token
      let name = Login.nickname
      
      // localStorage.setItem("token",JSON.stringify(this.usertoken))
      if(Login.code == 200){
        this.$router.replace("/operatingCenter");
        localStorage.setItem("token",JSON.stringify(this.usertoken))
        localStorage.setItem("name",JSON.stringify(Login.nickname))
        localStorage.setItem("imagea",Login._avatar)
        // localStorage.setItem("qx", JSON.stringify(this.navsrole));
        this.$notify({
          title: '成功',
          message: Login.msg,
          type: 'success'
        });
        this.indexa();
      }else{
        this.$notify.error({
          title: '错误',
          message: Login.msg
        });
      }
      this.navsrole = Login.navs
      localStorage.setItem("qx", JSON.stringify(this.navsrole));
      
    },
    async indexa (){
      let lists = await this.$api.home.indexa()
    },
    remember(){
    },
  }
};
</script>
<style scoped lang="less">
@import "~@views/login.less";
</style>